//首页-轮播图
const SWIPERDATA_URL = "/home/swiperdata"
//首页-导航栏
const CATITEMS_URL = "/home/catitems"
//首页-楼层
const FLOORDATA_URL = "/home/floordata"

//分类
const CATEGORY_URL = "/categories"

//商品列表
const GOODS_LIST = "/goods/search"

//商品详情页
const GOODS_DETAIL = "/goods/detail"

//获取用户token
const USER_WXLOGIN = '/users/wxlogin'

//创建订单
const MY_ORDERS_CREATE = '/my/orders/create'

//获取支付参数
const MY_ORDERS_REQ_UNIFIEDORDER = '/my/orders/req_unifiedorder'

//查看订单支付状态
const MY_ORDERS_CHKORDER = '/my/orders/chkOrder'

//历史订单查询
const MY_ORDERS_ALL = '/my/orders/all'

//token
const token = uni.getStorageSync('token') || ''
const install = (Vue, vm) => {
	// 此处没有使用传入的params参数
	// let getSearch = (params = {}) => vm.$u.get(hotSearchUrl, {
	// 	id: 2
	// });

	// 此处使用了传入的params参数，一切自定义即可
	let getSwiper = (params = {}) => vm.$u.get(SWIPERDATA_URL, params);
	let getCatitems = (params = {}) => vm.$u.get(CATITEMS_URL, params);
	let getFloor = (params = {}) => vm.$u.get(FLOORDATA_URL, params);
	let getcategory = (params = {}) => vm.$u.get(CATEGORY_URL, params);
	let getGoods = (params = {}) => vm.$u.get(GOODS_LIST, params);
	let getGoodsDetail = (params = {}) => vm.$u.get(GOODS_DETAIL, params);
	let getUserToken = (params = {}) => vm.$u.post(USER_WXLOGIN, params);
	let createOrder = (params = {}) => vm.$u.post(MY_ORDERS_CREATE, params, {
		Authorization: token,
	})
	let orderPayParams = (params = {}) => vm.$u.post(MY_ORDERS_REQ_UNIFIEDORDER, params, {
		Authorization: token,
	})
	let orderCheck = (params = {}) => vm.$u.post(MY_ORDERS_CHKORDER, params, {
		Authorization: token,
	})
	let getOrderList = (params = {}) => vm.$u.get(MY_ORDERS_ALL, params, {
		Authorization: token,
	})

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = { getSwiper, getCatitems, getFloor, getcategory, getGoods, getGoodsDetail, getUserToken, createOrder, orderPayParams, orderCheck, getOrderList };
}

export default {
	install
}